package com.qifenqian.turbot.module.adapter.restaurant

import com.chad.library.adapter.base.BaseItemDraggableAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.qifenqian.turbot.R
import com.qifenqian.turbot.module.entity.response.dish.CategoryEntity
import kotlinx.android.synthetic.main.item_dish_category_manage.view.*

/**
 * @author H
 * @createTime 2018/12/24 16:09
 * @description
 * @see
 * @since
 */
class DishCategoryManageAdapter(data: List<CategoryEntity>) : BaseItemDraggableAdapter<CategoryEntity, BaseViewHolder>(R.layout.item_dish_category_manage, data) {

    override fun convert(helper: BaseViewHolder, item: CategoryEntity) {
        val view = helper.itemView
        view.tv_item_dish_category_manage_name.text = item.dishTypeName
        view.btn_item_dish_category_manage_edit.setOnClickListener {
            if (mOnItemChildClickListener != null) {
                mOnItemChildClickListener!!.onEditClick(helper.layoutPosition)
            }
        }
        view.btn_item_dish_category_manage_delete.setOnClickListener {
            if (mOnItemChildClickListener != null) {
                mOnItemChildClickListener!!.onDeleteClick(helper.layoutPosition)
            }
        }
    }

    private var mOnItemChildClickListener: OnItemChildClickListener? = null
    fun setOnItemChildClickListener(listener: OnItemChildClickListener) {
        mOnItemChildClickListener = listener
    }

    interface OnItemChildClickListener {
        fun onEditClick(position: Int)
        fun onDeleteClick(position: Int)
    }
}
